﻿<?php defined('SYSPATH') or die('No direct script access.');

class Flash {

	const ERROR = 'error';
	const SUCCESS = 'success';
	const INFO = 'info';

	public static function message($type, $string)
	{
		$message[$type] = $string;
		Session::instance()->set('message', $message);
	}
	
	public static function render()
	{
		$message = Session::instance()->get('message');
		
		Session::instance()->delete('message');
		
		if(isset($message[self::SUCCESS])){
			$type = self::SUCCESS;
		}
		
		if(isset($message[self::ERROR])){
			$type = self::ERROR;
		}
		
		if(isset($message[self::INFO])){
			$type = self::INFO;
		}
		
		return isset($type) ?
			'<div class="alert alert-'.$type.'">'.
			'<a class="close" data-dismiss="alert">×</a>'.
			'<h4 class="alert-heading">Atenção!</h4>'.
			$message[$type].
			'</div>': '';
	}

}